package example.agent;

import example.Interceptor.TimingInterceptor;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.matcher.ElementMatchers;

import java.lang.instrument.Instrumentation;

/**
 * TODO
 *
 * @author lizhifu
 * @since 2023/4/25
 */
public class TimerAgent {

	public static void premain(String arguments, Instrumentation instrumentation) {
		new AgentBuilder.Default().type(ElementMatchers.nameEndsWith("Controller"))
			.transform((builder, type, classLoader, module, protectionDomain) -> builder.method(ElementMatchers.any())
				.intercept(MethodDelegation.to(TimingInterceptor.class)))
			.installOn(instrumentation);
	}

}